package com.sixdoors.business.controller;

import com.sixdoors.business.domain.ArticlePart;
import com.sixdoors.business.service.IArticlePartService;
import com.sixdoors.common.annotation.Log;
import com.sixdoors.common.core.controller.BaseController;
import com.sixdoors.common.core.domain.AjaxResult;
import com.sixdoors.common.core.page.TableDataInfo;
import com.sixdoors.common.enums.BusinessType;
import com.sixdoors.common.utils.poi.ExcelUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 文章相关Controller
 * 
 * @author sixdoors
 * @date 2024-04-08
 */
@Api("文章相关Controller")
@RestController
@RequestMapping("/business/article_part")
public class ArticlePartController extends BaseController
{
    @Autowired
    private IArticlePartService articlePartService;

    /**
     * 查询文章部位列表
     */
    @GetMapping("/list")
    @ApiOperation("查询文章列表")
    public TableDataInfo list(ArticlePart articlePart)
    {
        startPage();
        List<ArticlePart> list = articlePartService.selectArticlePartList(articlePart);
        return getDataTable(list);
    }

    /**
     * 导出文章部位列表
     */
    @PreAuthorize("@ss.hasPermi('business:article_part:export')")
    @Log(title = "文章部位", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ArticlePart articlePart)
    {
        List<ArticlePart> list = articlePartService.selectArticlePartList(articlePart);
        ExcelUtil<ArticlePart> util = new ExcelUtil<ArticlePart>(ArticlePart.class);
        util.exportExcel(response, list, "文章部位数据");
    }

    /**
     * 获取文章部位详细信息
     */
    @GetMapping(value = "/{id}")
    @ApiOperation("查询文章详细信息")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(articlePartService.selectArticlePartById(id));
    }

    /**
     * 新增文章
     */
    @Log(title = "文章", businessType = BusinessType.INSERT)
    @ApiOperation("新增文章")
    @PostMapping
    public AjaxResult add(@RequestBody ArticlePart articlePart)
    {
        return toAjax(articlePartService.insertArticlePart(articlePart));
    }

    /**
     * 修改文章
     */
    @Log(title = "文章部位", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation("修改文章")
    public AjaxResult edit(@RequestBody ArticlePart articlePart)
    {
        return toAjax(articlePartService.updateArticlePart(articlePart));
    }

    /**
     * 删除文章部位
     */
    @PreAuthorize("@ss.hasPermi('business:article_part:remove')")
    @Log(title = "文章部位", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(articlePartService.deleteArticlePartByIds(ids));
    }
}
